//
//  HomeC.m
//  ShopDemo
//
//  Created by 飞扬的青春 on 2018/7/3.
//  Copyright © 2018年 飞扬的青春. All rights reserved.
//

#import "HomeC.h"
#import "FirstOneCell.h"
#import "FirstTwoCell.h"
#import "HomeMoreC.h"
#import "CustomCollectionVC.h"
#import "FirDetailController.h"
#import "XSQGController.h"
#import "ShopDetailController.h"
#import "SearchController.h"
#import "TuiJianView.h"
#import "FirstTwoCollViewCell.h"
#import "CollectionHeaderView.h"
#import "FirstOneCollectionCell.h"
#import "FirstThirdCollectionViewCell.h"
#import "ShopDetailController.h"
#import "DLScrollTabbarView.h"
#import "DLUtility.h"
#import "DLLRUCache.h"
#import "DLCustomSlideView.h"
@interface HomeC ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,DLCustomSlideViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *listCollecitonview;
@property (weak, nonatomic) IBOutlet UITableView *listTableview;
//@property(nonatomic,strong)UITableView *listTableview;
@property(nonatomic,strong)NSArray *buttonArray;//按钮数组
@property(nonatomic,strong)NSArray *SDCArray;//轮播图数组
@property(nonatomic,strong)NSArray *sdcUrlArray;//轮播图网址
@property(nonatomic,strong)NSArray *xsArray;//限时抢购广告数组
@property(nonatomic,strong)NSArray *xsBtnArray;//限时抢购按钮数组
@property(nonatomic,strong)NSArray *xsCountArray;//显示抢购内容
@property(nonatomic,strong)NSArray *tjArray;//推荐数组
@property(nonatomic,strong)UIView *headerView;
@property(nonatomic,strong)NSArray *pageArray;//分页广告图

@property(nonatomic,strong)SDCycleScrollView *cycleScrollView;
@property(nonatomic,strong)DLCustomSlideView *slideView;

@end

@implementation HomeC
-(void)viewWillAppear:(BOOL)animated{
   
}
-(void)viewWillDisappear:(BOOL)animated{
    
}


-(void)searchItemAction:(UIBarButtonItem *)item{
    SearchController *scvc = [[SearchController alloc]init];
    scvc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:scvc animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //限时抢购内容
    //[self showXSButtonImageDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:@"/dashop/seckill/app/getSecKill.do"]];
    //顶部轮播
    [self showDataSDCycleMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:@"/dashop/advertise/app/advertisePic.do?ADV_FLAG=A1"]];
    [self showDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:@"/dashop/category/app/list.do?SUPER_ID=0"]];
    
//    [self showImageDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:@"/dashop/advertise/app/advertisePic.do?ADV_FLAG=A2"]];
//    [self showTJButtonImageDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:@"/dashop/goods/app/list.do?GOODS_HOT=1"]];
//    [self PageshowImageDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:@"/dashop/advertise/app/advertisePic.do?ADV_FLAG=FL"]];
    
    
    UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"search.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(searchItemAction:)];
    self.navigationItem.rightBarButtonItem = right;
    
    //顶部轮播
    _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 200*kJLXWidthScale) delegate:self placeholderImage:[UIImage imageNamed:@"FirstPlace.jpg"]];
    _cycleScrollView.autoScrollTimeInterval = 2.0;
    [self.view addSubview:_cycleScrollView];
//    [self addTabPageViewController];
    
  
//    [self creatCollectionViewMethod];
    
}


-(void)creatCollectionViewMethod{
    
    self.listCollecitonview.delegate = self;
    self.listCollecitonview.dataSource = self;
    self.listCollecitonview.backgroundColor = [UIColor whiteColor];
    [self.listCollecitonview registerClass :[UICollectionViewCell class ] forCellWithReuseIdentifier : @"onecell" ];
    [self.listCollecitonview registerClass :[UICollectionViewCell class ] forCellWithReuseIdentifier : @"twocell" ];
    [self.listCollecitonview registerClass :[FirstThirdCollectionViewCell class ] forCellWithReuseIdentifier : @"thirdcell" ];
    [self.listCollecitonview registerClass :[UICollectionViewCell class ] forCellWithReuseIdentifier : @"fourcell" ];
    [self.listCollecitonview registerClass :[UICollectionViewCell class ] forCellWithReuseIdentifier : @"fivecell" ];
     [self.listCollecitonview registerClass :[FirstOneCollectionCell class ] forCellWithReuseIdentifier : @"sixcell" ];
    //注册页眉
    [self.listCollecitonview registerClass:[CollectionHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
}


-(void)addTabedSLideView{
    DLLRUCache *cache = [[DLLRUCache alloc] initWithCount:6];
    DLScrollTabbarView *tabbar = [[DLScrollTabbarView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 34)];
    tabbar.tabItemNormalColor = [UIColor blackColor];
    tabbar.tabItemSelectedColor = [UIColor redColor];
    tabbar.tabItemNormalFontSize = 14.0f;
    tabbar.trackColor = [UIColor redColor];
    NSMutableArray *items = [NSMutableArray arrayWithCapacity:self.buttonArray.count];
    for (int i = 0; i < self.buttonArray.count; i++) {
        NSDictionary *dic = self.buttonArray[i];
        DLScrollTabbarItem *item = [DLScrollTabbarItem itemWithTitle:dic[@"CATEGORY_NAME"] width:80];
        [items addObject:item];
        
    }
    tabbar.tabbarItems = items;
    
    
    self.slideView = [[DLCustomSlideView alloc]initWithFrame:CGRectMake(0, 200*kJLXWidthScale , kScreenWidth, kScreenHeight - 200*kJLXWidthScale)];
    [self.view addSubview:self.slideView];
    self.slideView.delegate = self;
    self.slideView.tabbar = tabbar;
    self.slideView.cache = cache;
    self.slideView.tabbarBottomSpacing = 5;
    self.slideView.baseViewController = self;
    [self.slideView setup];
    self.slideView.selectedIndex = 0;
    

//    self.tabedSlideView.tabItemNormalColor = [UIColor blackColor];
//    self.tabedSlideView.tabItemSelectedColor = [UIColor colorWithRed:0.833 green:0.052 blue:0.130 alpha:1.000];
//    self.tabedSlideView.tabbarTrackColor = [UIColor colorWithRed:0.833 green:0.052 blue:0.130 alpha:1.000];
//    self.tabedSlideView.tabbarBackgroundImage = [UIImage imageNamed:@"tabbarBk"];
//    self.tabedSlideView.tabbarBottomSpacing = 3.0;
//    NSMutableArray *items = [NSMutableArray arrayWithCapacity:5];
//    for (int i = 0; i < self.buttonArray.count; i++) {
//        NSDictionary *dic = self.buttonArray[i];
//        DLTabedbarItem *item = [DLTabedbarItem itemWithTitle:dic[@"CATEGORY_NAME"] image:nil selectedImage:nil];
//        [items addObject:item];
//
//    }
//
//    self.tabedSlideView.tabbarItems = items;
//    [self.tabedSlideView buildTabbar];
//    self.tabedSlideView.selectedIndex = 0;
}

- (NSInteger)numberOfTabsInDLCustomSlideView:(DLCustomSlideView *)sender{
    return [self.buttonArray count];
}

- (UIViewController *)DLCustomSlideView:(DLCustomSlideView *)sender controllerAt:(NSInteger)index{
    NSDictionary *dic = self.buttonArray[index];
    FirDetailController *vc = [[FirDetailController alloc]init];
    vc.navigationItem.title = dic[@"CATEGORY_NAME"];
    NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/list.do?SUPER_ID=%@",dic[@"CATEGORY_ID"]];
    vc.urlStr = urlstr;
    return  vc;
}

#pragma mark--------------------UICollectionViewDelegateFlowLayout,UICollectionViewDelegate, UICollectionViewDataSource
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return self.buttonArray.count + 4;
}

//cell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 10;
    }else if(section == 2){
        if (self.xsArray.count > 0) {
            return self.xsBtnArray.count;
        }else{
            return 0;
        }
    }else if(section == self.buttonArray.count + 4 -1){
      return  self.tjArray.count;
    }else{
        NSDictionary *dic = self.buttonArray[section - 3];
        NSArray *arr = dic[@"SON"];
        if ([dic[@"CATEGORY_NAME"]isEqualToString:@"一元抢购"]) {
            return 1;
        }else{
            return arr.count + 1;
        }
    }
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"onecell" forIndexPath:indexPath];
        SDCycleScrollView *cycleScrollView3 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 200*kJLXWidthScale) delegate:self placeholderImage:[UIImage imageNamed:@"FirstPlace.jpg"]];
        cycleScrollView3.imageURLStringsGroup = self.sdcUrlArray;
        cycleScrollView3.autoScrollTimeInterval = 2.0;
        [cell.contentView addSubview:cycleScrollView3];
        return cell;
    }else if (indexPath.section == 1){
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"twocell" forIndexPath:indexPath];
        [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        UIImageView *imagevi = [UIImageView new];
        imagevi.contentMode = UIViewContentModeScaleAspectFill;
        [cell.contentView addSubview:imagevi];
        imagevi.sd_layout
        .topSpaceToView(cell.contentView, 10*kJLXWidthScale)
        .centerXEqualToView(cell.contentView)
        .heightIs(kScreenWidth/5-30*kJLXWidthScale)
        .widthIs(kScreenWidth/5 - 30*kJLXWidthScale);
        UILabel *lab = [UILabel new];
        lab.font = [UIFont systemFontOfSize:15*kJLXWidthScale];
        lab.textColor = [UIColor blackColor];
        lab.textAlignment = NSTextAlignmentCenter;
        [cell.contentView addSubview:lab];
        lab.sd_layout
        .topSpaceToView(imagevi, 10*kJLXWidthScale)
        .centerXEqualToView(cell.contentView)
        .heightIs(20*kJLXWidthScale)
        .widthIs(kScreenWidth/5);
        if (indexPath.row < 9) {
            NSDictionary *dic = self.buttonArray[indexPath.row];
            NSURL *uRL = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"CATEGORY_IMG"]]];
            [imagevi sd_setImageWithURL:uRL];
            lab.text = dic[@"CATEGORY_NAME"];
        }else{
            imagevi.image = [UIImage imageNamed:@"More.png"];
            lab.text = @"更多";
        }
        return cell;
    }else if (indexPath.section == 2){
//         UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"thirdcell" forIndexPath:indexPath];
//        [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
        FirstThirdCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"thirdcell" forIndexPath:indexPath];
        NSDictionary *dic = self.xsBtnArray[indexPath.row];
        NSURL *url = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"GOODS_PIC"]]];
        [cell.titImageview sd_setImageWithURL:url];
        cell.titlab.sd_layout
        .heightIs(20*kJLXWidthScale);
        cell.titlab.text = [NSString stringWithFormat:@"%@",dic[@"GOODS_NAME"]];
        cell.titlab.textColor = [UIColor darkGrayColor];
        cell.pricelab.text = [NSString stringWithFormat:@"￥：%@",dic[@"GOODS_PRICE"]];
        cell.pricelab.textColor = [UIColor orangeColor];
        return cell;
    }else if(indexPath.section == self.buttonArray.count + 4 -1 && self.buttonArray.count > 0){
        FirstOneCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"sixcell" forIndexPath:indexPath];
        NSDictionary *dic = self.tjArray[indexPath.row];
        cell.titImageview.frame = CGRectMake(0, 0,kScreenWidth / 2-2-50*kJLXWidthScale, kScreenWidth / 2-2-50*kJLXWidthScale);
        cell.titImageview.center = cell.contentView.center;
        NSURL *url = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"GOODS_PIC"]]];
        [cell.titImageview sd_setImageWithURL:url];
        cell.titlab.text = [NSString stringWithFormat:@"%@",dic[@"GOODS_NAME"]];
        cell.pricelab.textColor = [UIColor orangeColor];
        cell.pricelab.text = [NSString stringWithFormat:@"￥%@",dic[@"GOODS_MINPRICE"]];
        return cell;
    }else{
        if (indexPath.row == 0) {
            UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"fourcell" forIndexPath:indexPath];
             [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            UIImageView *imagevi = [UIImageView new];
            [cell.contentView addSubview:imagevi];
            imagevi.sd_layout
            .topSpaceToView(cell.contentView,0)
            .leftSpaceToView(cell.contentView, 0)
            .rightSpaceToView(cell.contentView, 0)
            .heightIs(180*kJLXWidthScale);
            NSDictionary *pagedic = self.pageArray[indexPath.section - 3];
            NSString *str = [MethodClass returnUrlSetStrWSDLURL:pagedic[@"ADVERTISE_PIC"]];
            [imagevi sd_setImageWithURL:[NSURL URLWithString:str]];
            return cell;
        }else{
            NSDictionary *maindic = self.buttonArray[indexPath.section - 3];
            NSArray *arr = maindic[@"SON"];
             UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"fivecell" forIndexPath:indexPath];
            
            NSDictionary *dic = arr[indexPath.row-1];
            NSURL *url = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"CATEGORY_IMG"]]];
            [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            UIImageView *imagevi = [[UIImageView alloc]initWithFrame:CGRectMake(0, 8*kJLXWidthScale,cell.frame.size.width - 30*kJLXWidthScale,cell.frame.size.width - 30*kJLXWidthScale)];
            [imagevi sd_setImageWithURL:url];
            imagevi.contentMode = UIViewContentModeScaleAspectFill;
            [cell.contentView addSubview:imagevi];
            UILabel *lab = [UILabel new];
            lab.font = [UIFont systemFontOfSize:15*kJLXWidthScale];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.textColor = [UIColor blackColor];
           lab.text = [NSString stringWithFormat:@"%@",dic[@"CATEGORY_NAME"]];
            [cell.contentView addSubview:lab];
            lab.sd_layout
            .bottomSpaceToView(cell.contentView, 0)
            .centerXEqualToView(imagevi)
            .widthRatioToView(imagevi, 1)
            .heightIs(20*kJLXWidthScale);
            return cell;
        }
        
    }
    
    
}

//返回页脚或页脚视图 重用
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        CollectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
        if (indexPath.section == self.buttonArray.count + 4 - 1 && self.buttonArray.count > 0) {
           [headerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            UILabel *lab = [UILabel new];
            lab.text = @"为你推荐";
            lab.font = [UIFont systemFontOfSize:20*kJLXWidthScale];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.textColor = [UIColor redColor];
            [headerView addSubview:lab];
            lab.sd_layout
            .topSpaceToView(headerView, 0)
            .centerXEqualToView(headerView)
            .widthIs(kScreenWidth/2)
            .heightIs(40*kJLXWidthScale);
            return headerView;
        }else if(indexPath.section == 2 && self.xsBtnArray.count > 0){
            [headerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, headerView.height)];
            backview.backgroundColor = [UIColor whiteColor];
            [headerView addSubview:backview];
            UILabel *titlab = [UILabel new];
            titlab.font = [UIFont systemFontOfSize:20*kJLXWidthScale];
            titlab.textColor = [UIColor redColor];
            [backview addSubview:titlab];
            titlab.sd_layout
            .centerXEqualToView(backview)
            .leftSpaceToView(backview, 8*kJLXWidthScale)
            .heightIs(backview.height)
            .widthIs(kScreenWidth/3);
            
            UILabel *rilab = [UILabel new];
            rilab.text = @"查看更多>>";
            rilab.font = [UIFont systemFontOfSize:16*kJLXWidthScale];
            rilab.textAlignment = NSTextAlignmentRight;
            rilab.textColor = [UIColor blackColor];
            [backview addSubview:rilab];
            rilab.sd_layout
            .centerXEqualToView(backview)
            .rightSpaceToView(backview, 8*kJLXWidthScale)
            .heightIs(backview.height)
            .widthIs(kScreenWidth/3);
            NSDictionary *dic = self.buttonArray[indexPath.section ];
            titlab.text = [NSString stringWithFormat:@"%@",@"限时抢购"];
            MyGestureTap*tap = [[MyGestureTap alloc]initWithTarget:self action:@selector(bagtypetap:)];
            tap.userInfo = dic;
            rilab.userInteractionEnabled = YES;
            [rilab addGestureRecognizer:tap];
            return headerView;
        }else{
             [headerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, headerView.height)];
            backview.backgroundColor = [UIColor whiteColor];
            [headerView addSubview:backview];
            UILabel *titlab = [UILabel new];
            titlab.font = [UIFont systemFontOfSize:20*kJLXWidthScale];
            titlab.textColor = [UIColor redColor];
            [backview addSubview:titlab];
            titlab.sd_layout
            .centerXEqualToView(backview)
            .leftSpaceToView(backview, 8*kJLXWidthScale)
            .heightIs(backview.height)
            .widthIs(kScreenWidth/3);
            
            UILabel *rilab = [UILabel new];
            rilab.text = @"查看更多>>";
            rilab.font = [UIFont systemFontOfSize:16*kJLXWidthScale];
            rilab.textAlignment = NSTextAlignmentRight;
            rilab.textColor = [UIColor blackColor];
            [backview addSubview:rilab];
            rilab.sd_layout
            .centerXEqualToView(backview)
            .rightSpaceToView(backview, 8*kJLXWidthScale)
            .heightIs(backview.height)
            .widthIs(kScreenWidth/3);
            NSDictionary *dic = self.buttonArray[indexPath.section - 3];
            titlab.text = [NSString stringWithFormat:@"%@",dic[@"CATEGORY_NAME"]];
            MyGestureTap*tap = [[MyGestureTap alloc]initWithTarget:self action:@selector(bagtypetap:)];
            tap.userInfo = dic;
            rilab.userInteractionEnabled = YES;
            [rilab addGestureRecognizer:tap];
            return headerView;
        }
    }else{
        UICollectionReusableView *footer = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];
        footer.backgroundColor = [UIColor whiteColor];
        return footer;
    }
    
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    if (section > 1) {
        if (section == 2) {
            if (self.xsBtnArray.count > 0) {
                return CGSizeMake(kScreenWidth, 40*kJLXWidthScale);
            }else{
               return CGSizeMake(0, 0);
            }
        }else{
            return CGSizeMake(kScreenWidth, 40*kJLXWidthScale);
        }
    }else{
         return CGSizeMake(0, 0);
    }
}
#pragma mark-------------------布局代理
//设置每个cell的宽和高
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return CGSizeMake(kScreenWidth, 200*kJLXWidthScale);
    }else if (indexPath.section == 1){
        return CGSizeMake(kScreenWidth/5, kScreenWidth/5 + 10*kJLXWidthScale);
    }else if (indexPath.section == 2){
        if (self.xsBtnArray.count > 0) {
            return CGSizeMake(kScreenWidth / 3 -1, kScreenWidth /3);
        }else{
            return CGSizeMake(0, 0);
        }
    }else if(indexPath.section == self.buttonArray.count + 4 - 1){
        return CGSizeMake(kScreenWidth / 2-2, kScreenWidth / 2-2);
    }else{
        if (indexPath.row == 0) {
            return CGSizeMake(kScreenWidth, 180*kJLXWidthScale);
        }else{
            return CGSizeMake(kScreenWidth / 3, kScreenWidth /3);
        }
    }
}
//设置分区缩进
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    if (section == 0) {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }else if(section == self.buttonArray.count + 4 - 1 && self.buttonArray.count > 0){
        return UIEdgeInsetsMake(0, 0, 50*kJLXWidthScale, 0);
    }else{
        return UIEdgeInsetsMake(0, 0, 15*kJLXWidthScale, 0);
    }
}
//设置每个分区之间最小的行间距和列间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 3;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}
#pragma mark--------------------------cell点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        if (indexPath.row < 9) {
            NSDictionary *dic = self.buttonArray[indexPath.row];
            FirDetailController *detailVC = [[FirDetailController alloc]init];
            detailVC.navigationItem.title = dic[@"CATEGORY_NAME"];
            NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/list.do?SUPER_ID=%@",dic[@"CATEGORY_ID"]];
            detailVC.urlStr = urlstr;
            detailVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:detailVC animated:YES];
        }else{
            HomeMoreC *moreVC = [[HomeMoreC alloc]init];
            moreVC.navigationItem.title = @"更多产品";
            moreVC.moreArray = self.buttonArray;
            moreVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:moreVC animated:YES];
        }
    }else if (indexPath.section == 2){
        NSDictionary *xsDic = self.xsBtnArray[indexPath.row];
        ShopDetailController *devc = [[ShopDetailController alloc]init];
        devc.hidesBottomBarWhenPushed = YES;
        NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/getGoods?GOODS_ID=%@",xsDic[@"GOODS_ID"]];
        devc.urlStr = urlstr;
        devc.usdic = xsDic;
        [self.navigationController pushViewController:devc animated:YES];
    }else if (indexPath.section == self.buttonArray.count + 4 - 1 && self.buttonArray.count > 0){
         NSDictionary *conDic = self.tjArray[indexPath.row];
        ShopDetailController *devc = [[ShopDetailController alloc]init];
        devc.navigationItem.title = conDic[@"CATEGORY_NAME"];
        devc.hidesBottomBarWhenPushed = YES;
        NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/getGoods?GOODS_ID=%@",conDic[@"GOODS_ID"]];
        devc.urlStr = urlstr;
        devc.usdic = conDic;
        [self.navigationController pushViewController:devc animated:YES];
    }else{
        if (indexPath.row > 0) {
            NSDictionary *maindic = self.buttonArray[indexPath.section - 3];
            NSArray *arr = maindic[@"SON"];
            NSDictionary *conDic = arr[indexPath.row-1];
            FirDetailController *detailVC = [[FirDetailController alloc]init];
            detailVC.navigationItem.title = conDic[@"CATEGORY_NAME"];
            NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/list.do?GOODS_CATEGORY=%@&CurrentPage=1",conDic[@"CATEGORY_ID"]];
            detailVC.urlStr = urlstr;
            detailVC.dic = conDic;
            detailVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:detailVC animated:YES];
        }
    }
    
}















-(void)createTableviewMethod{
//    self.listTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-120*kJLXWidthScale) style:UITableViewStylePlain];
//    [self.view addSubview:self.listTableview];
//    if (kScreenHeight == 812) {
//        self.listTableview.sd_layout
//        .bottomSpaceToView(self.view, 34);
//    }
    self.listTableview.dataSource = self;
    self.listTableview.delegate = self;
    [self.listTableview registerClass:[FirstOneCell class] forCellReuseIdentifier:@"onecell"];
    [self.listTableview registerClass:[FirstTwoCell class] forCellReuseIdentifier:@"twocell"];
    //分隔线
    self.listTableview.separatorStyle = UITableViewCellAccessoryNone;
    //去掉尾部多余的空白
    [self.listTableview setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    
}

-(void)creatHeaderViewMethod{
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, (203 + kScreenWidth/5*2)*kJLXWidthScale + 180*kJLXWidthScale)];
    self.headerView.backgroundColor = LineBackColor;
    self.listTableview.tableHeaderView = self.headerView;

}

-(void)showDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
    self.buttonArray = response;
        [self addTabedSLideView];
//        [self addTabPageViewController];
//        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
//            NSInteger distanceWD = kScreenWidth/5;
//            for (int i = 0; i < 5; i ++) {
//                NSDictionary *dic = self.buttonArray[i];
//                MyButton *btn = [[MyButton alloc]initWithFrame:CGRectMake(distanceWD*i, 203*kJLXWidthScale, distanceWD, distanceWD)];
//                NSURL *uRL = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"CATEGORY_IMG"]]];
//                [btn.imageV sd_setImageWithURL:uRL];
//                btn.titlab.text = dic[@"CATEGORY_NAME"];
//                btn.backgroundColor = [UIColor whiteColor];
//                btn.usinfo = dic;
//                [btn addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//                [self.headerView addSubview:btn];
//            }
//
//            for (int i = 0; i < 5; i ++) {
//                MyButton *btn = [[MyButton alloc]initWithFrame:CGRectMake(distanceWD*i, 203*kJLXWidthScale + distanceWD, distanceWD, distanceWD)];
//                if (i < 4) {
//                    NSDictionary *dic = self.buttonArray[i + 5];
//                    NSURL *uRL = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"CATEGORY_IMG"]]];
//                    [btn.imageV sd_setImageWithURL:uRL];
//                    btn.titlab.text = dic[@"CATEGORY_NAME"];
//                    btn.usinfo = dic;
//                    [btn addTarget:self action:@selector(headerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//
//                }else{
//                    btn.titlab.text = @"更多";
//                    btn.imageV.image = [UIImage imageNamed:@"More.png"];
//                    [btn addTarget:self action:@selector(moreButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//                }
//                btn.backgroundColor = [UIColor whiteColor];
//                [self.headerView addSubview:btn];
//            }
//
//
//        }];
//        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
//            [self.listTableview reloadData];
//            [self.listCollecitonview reloadData];
//        }];
        
    } failBlock:^(NSError *error) {
        
    }];
}


-(void)headerButtonAction:(MyButton *)sender{
    
    FirDetailController *detailVC = [[FirDetailController alloc]init];
    detailVC.navigationItem.title = sender.usinfo[@"CATEGORY_NAME"];
    NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/list.do?SUPER_ID=%@",sender.usinfo[@"CATEGORY_ID"]];
    detailVC.urlStr = urlstr;
    detailVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:detailVC animated:YES];
    
}

-(void)moreButtonAction:(MyButton *)sender{
    HomeMoreC *moreVC = [[HomeMoreC alloc]init];
    moreVC.moreArray = self.buttonArray;
    moreVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:moreVC animated:YES];
    
}

-(void)showDataSDCycleMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.SDCArray = response;
        NSMutableArray *imagesURLStrings = [NSMutableArray arrayWithCapacity:10];
        for (NSDictionary *dic in self.SDCArray) {
            NSString *url = [MethodClass returnUrlSetStrWSDLURL:dic[@"ADVERTISE_PIC"]];
            [imagesURLStrings addObject:url];
        }
        self.sdcUrlArray = [imagesURLStrings copy];
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
//            SDCycleScrollView *cycleScrollView3 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 200*kJLXWidthScale) delegate:self placeholderImage:[UIImage imageNamed:@"FirstPlace.jpg"]];
//            cycleScrollView3.imageURLStringsGroup = imagesURLStrings;
//            cycleScrollView3.autoScrollTimeInterval = 2.0;
//            [self.headerView addSubview:cycleScrollView3];
            
            self.cycleScrollView.imageURLStringsGroup = imagesURLStrings;
//            [self.listCollecitonview reloadData];
        }];
        
        
    } failBlock:^(NSError *error) {
        
    }];
    
}
//限时抢购广告图
-(void)showImageDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.xsArray = response;
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            
            UIImageView *imView = [[UIImageView alloc]initWithFrame:CGRectMake(0, (203 + kScreenWidth/5*2)*kJLXWidthScale, kScreenWidth, 180*kJLXWidthScale)];
            NSDictionary *dic = self.xsArray[0];
            NSURL *uRL = [NSURL URLWithString:[MethodClass returnUrlSetStrWSDLURL:dic[@"ADVERTISE_PIC"]]];
            [imView sd_setImageWithURL:uRL];
            [self.headerView addSubview:imView];
            NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
            [self.listTableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
        }];
    } failBlock:^(NSError *error) {
        
    }];
    
}


//限时抢购按钮图
-(void)showXSButtonImageDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.xsCountArray = response;
        if (self.xsCountArray.count > 0) {
            NSDictionary *dic = self.xsCountArray[0];
            NSString *urlstr = [NSString stringWithFormat:@"/dashop/seckillgoods/app/getSecKillGoods.do?SECKILL_ID=%@",dic[@"SECKILL_ID"]];
            NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
            [self XSShopingDataMethodWithUrl:endstr];
        }
    } failBlock:^(NSError *error) {
        
    }];
    
}

-(void)XSShopingDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.xsBtnArray = response;
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            [self.listTableview reloadData];
            [self.listCollecitonview reloadData];
        }];
    } failBlock:^(NSError *error) {
        
    }];
    
}

//为你推荐
-(void)showTJButtonImageDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.tjArray = response;
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            [self.listCollecitonview reloadData];
            if (self.tjArray.count > 0) {
                //一个section刷新
                UIView *footview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, self.tjArray.count/2*(kScreenWidth / 2-2 + 60*kJLXWidthScale))];
                if (self.tjArray.count < 2) {
                    footview.frame = CGRectMake(0, 0, kScreenWidth, (kScreenWidth / 2-2 + 60*kJLXWidthScale));
                }
                TuiJianView *tuijianview = [[TuiJianView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth,footview.height)];
                tuijianview.dataArray = self.tjArray;
                [footview addSubview:tuijianview];
                __weak typeof(self)weakself = self;
                tuijianview.detailBlock = ^(NSDictionary *conDic) {
                    ShopDetailController *devc = [[ShopDetailController alloc]init];
                    devc.navigationItem.title = conDic[@"CATEGORY_NAME"];
                    devc.hidesBottomBarWhenPushed = YES;
                    NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/getGoods?GOODS_ID=%@",conDic[@"GOODS_ID"]];
                    devc.urlStr = urlstr;
                    devc.usdic = conDic;
                    [weakself.navigationController pushViewController:devc animated:YES];
                };
                self.listTableview.tableFooterView = footview;
            }
        }];
    } failBlock:^(NSError *error) {
        
    }];
    
}

//分页广告
-(void)PageshowImageDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.pageArray = response;
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:1];
            [self.listTableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
            [self.listCollecitonview reloadData];
        }];
    } failBlock:^(NSError *error) {
        
    }];
    
}

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"---点击了第%ld张图片", (long)index);
    NSDictionary *dic = self.SDCArray[index];
    KMLog(@"%@",dic);
    NSString *urlstr = [NSString stringWithFormat:@"/dashop/advertise/app/advertiseDetails.do?ADVERTISE_ID=%@",dic[@"ADVERTISE_ID"]];
    NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
    [self scdDetailViewDataMethodWithUrl:endstr];
}

//轮播图详情界面数据
-(void)scdDetailViewDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        NSDictionary *dic = response;
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            ShopDetailController *shopVC = [[ShopDetailController alloc]init];
            shopVC.hidesBottomBarWhenPushed = YES;
            shopVC.navigationItem.title = @"商品";
            NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/getGoods?GOODS_ID=%@&USER_ID=%@",dic[@"GOODS_ID"],[UserDefault objectForKey:LogUserID]];
            shopVC.urlStr = urlstr;
            shopVC.usdic = dic;
            [self.navigationController pushViewController:shopVC animated:YES];
        }];
    } failBlock:^(NSError *error) {
        
    }];
    
}

#pragma mark --UITableViewDelegate,UITableViewDataSource--

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 1) {
        return self.buttonArray.count;
    }else{
        if (self.xsBtnArray.count == 0) {
            return 0;
        }else{
            return 1;
        }
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(indexPath.section == 1){
        FirstTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"twocell" forIndexPath:indexPath];
        // 定义唯一标识
//        static NSString *CellIdentifier = @"Cell";
//        // 通过唯一标识创建cell实例
//         FirstTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//            // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
//        if (!cell) {
//            cell = [[FirstTwoCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
//        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;//cell选中以后的颜色
        NSDictionary *dic = self.buttonArray[indexPath.row];
        NSDictionary *pagedic = self.pageArray[indexPath.row];
        NSString *str = [MethodClass returnUrlSetStrWSDLURL:pagedic[@"ADVERTISE_PIC"]];
        [cell.imageVi sd_setImageWithURL:[NSURL URLWithString:str]];
        cell.leftlab.text = [NSString stringWithFormat:@"%@",dic[@"CATEGORY_NAME"]];
        NSArray *arr = dic[@"SON"];
        if ([dic[@"CATEGORY_NAME"]isEqualToString:@"一元抢购"]) {
            cell.dataArray = [NSArray array];
        }else{
            cell.dataArray = arr;
        }
        cell.detailBlock = ^(NSDictionary *conDic) {
            FirDetailController *detailVC = [[FirDetailController alloc]init];
            detailVC.navigationItem.title = conDic[@"CATEGORY_NAME"];
            NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/list.do?GOODS_CATEGORY=%@",conDic[@"CATEGORY_ID"]];
            detailVC.urlStr = urlstr;
            detailVC.dic = conDic;
            detailVC.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:detailVC animated:YES];
        };
        MyGestureTap*tap = [[MyGestureTap alloc]initWithTarget:self action:@selector(bagtypetap:)];
        tap.userInfo = dic;
        cell.rightlab.userInteractionEnabled = YES;
        [cell.rightlab addGestureRecognizer:tap];
        [cell.listCollectionview reloadData];
        return cell;
    }else{
        FirstOneCell*cell = [tableView dequeueReusableCellWithIdentifier:@"onecell" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;//cell选中以后的颜色
        cell.dataArray = self.xsBtnArray;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(XSmoreTapAction:)];
        cell.rightlab.userInteractionEnabled = YES;
        [cell.rightlab addGestureRecognizer:tap];
        __weak typeof(self)weakself = self;
        cell.xsBlock = ^(NSDictionary *xsDic) {
            ShopDetailController *devc = [[ShopDetailController alloc]init];
            devc.hidesBottomBarWhenPushed = YES;
            NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/getGoods?GOODS_ID=%@",xsDic[@"GOODS_ID"]];
            devc.urlStr = urlstr;
            devc.usdic = xsDic;
            [weakself.navigationController pushViewController:devc animated:YES];
        };
        
        return cell;
    }
    
    
}





-(void)tuijianButtonAction:(MyGestureTap *)tap{
    ShopDetailController *devc = [[ShopDetailController alloc]init];
    devc.navigationItem.title = tap.userInfo[@"CATEGORY_NAME"];
    devc.hidesBottomBarWhenPushed = YES;
    NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/getGoods?GOODS_ID=%@",tap.userInfo[@"GOODS_ID"]];
    devc.urlStr = urlstr;
    devc.usdic = tap.userInfo;
    [self.navigationController pushViewController:devc animated:YES];
}

//限时抢购更多
-(void)XSmoreTapAction:(UITapGestureRecognizer *)tap{
    XSQGController *vc = [[XSQGController alloc]init];
    vc.datasource = self.xsCountArray;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)goodsButtonAction:(MyButton *)sender{
    
}

//每个模块的更加
-(void)bagtypetap:(MyGestureTap *)tap{
    FirDetailController *detailVC = [[FirDetailController alloc]init];
    NSString *urlstr = [NSString stringWithFormat:@"/dashop/goods/app/list.do?SUPER_ID=%@",tap.userInfo[@"CATEGORY_ID"]];
    detailVC.navigationItem.title = tap.userInfo[@"CATEGORY_NAME"];
    detailVC.urlStr = urlstr;
    detailVC.dic = tap.userInfo[@"CATEGORY_NAME"];
    detailVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:detailVC animated:YES];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        NSDictionary *dic = self.buttonArray[indexPath.row];
        NSArray *arr = dic[@"SON"];
        if ([dic[@"CATEGORY_NAME"]isEqualToString:@"一元抢购"]) {
            return 40*kJLXWidthScale + 180*kJLXWidthScale;
        }else{
            if (arr.count < 4) {
                return kScreenWidth/3 + 50*kJLXWidthScale + 40*kJLXWidthScale + 180*kJLXWidthScale;
            }else{
                return kScreenWidth/3*2 + 50*kJLXWidthScale + 40*kJLXWidthScale + 180*kJLXWidthScale;
            }
        }
    }else{
         return 50*kJLXWidthScale + kScreenWidth/3;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
